function [data,data_trans] = generate_data_rand(N,J,mu_x,sigma_x,mu_z,sigma_z,alpha,beta,fractions)

% draw data

x = randn(N,J)*sigma_x + mu_x;
z = randn(N,J)*sigma_z + mu_z;

epsilon = -evrnd(0,1,[N,J]);

num_open = discretesample(fractions,N)';

choice = zeros(N,1);

for i=1:N
    
    VU = alpha*x(i,:) + epsilon(i,:);
    U = alpha*x(i,:) + beta*z(i,:) + epsilon(i,:);
    
    [~,ind_VU] = sort(VU,'descend');
    
    ind_open = ind_VU(1:num_open(i));
    ind_closed = setdiff(1:J,ind_open);
    
    U_new = U;
    U_new(ind_closed) = -Inf;
    
    [~,ind_good] = max(U_new);
    
    choice(i) = ind_good;
           
              
end

data.x = x;
data.z = z;
data.epsilon = epsilon;
data.choice = choice;
data.num_open = num_open;

data = struct2dataset(data);

data_trans = transform_data_01(data,J);

end

